package com.cssw.fyzb.core.dao.system;

import com.cssw.fyzb.core.model.dodb.SysParam;
import com.ydn.dbframe.plugin.activerecord.parse.SqlParse;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.Map;
import java.util.List;

/**
 * @author Feng Chen
 */
@Repository
public class SysParamDaoImpl implements SysParamDao {

    @Override
    public SysParam findByCode(String paramCode) {
        Map<String, Object> param = new HashMap<>();
        param.put("paramCode", paramCode);
        SqlParse sqlParse = new SqlParse(param);
        sqlParse.addSQL("SELECT * FROM  sys_param ");
        sqlParse.addSQL(" WHERE param_code = :paramCode");
        return SysParam.dao.findFirst(sqlParse);
    }

    @Override
    public List<SysParam> list() {
        return SysParam.dao.findAll();
    }

    @Override
    public boolean update(String paramCode, String paramValue) {
        SysParam sysParam = findByCode(paramCode);
        sysParam.setParamValue(paramValue);
        return sysParam.update();
    }
}
